package core.plugins;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * This class will do all of the installation of
 * the Plugins.
 * 
 * @author Spencer
 *
 */

public class PluginInstaller 
{
	/**
	 * This is a static function that will install a plugin.
	 * It will then return the IProductIDPlugin instance to
	 * the caller who can then do what he wants with it.
	 * 
	 * @param pluginToInstall A string containing the name
	 * 		of the concrete plugin class.
	 * 
	 * @return Returns the created plugin to the caller. If there
	 * 		was an error installing the plugin null is returned.
	 */
	public static IProductIDPlugin installPlugin(String pluginToInstall)
	{
		System.out.println("Installing plugin (" + pluginToInstall + ")");
		
		//Class newPluginClass;
		try 
		{
			Class newPluginClass = Class.forName(pluginToInstall);
			Object newPlugin = newPluginClass.newInstance();
			
			return (IProductIDPlugin) newPlugin;
		}
		catch (Exception e) 
		{
			//ClassNotFoundException | SecurityException | InstantiationException | 
			//IllegalAccessException | IllegalArgumentException
			System.out.println("ERROR LOADING PLUGIN: " + pluginToInstall);
		}
		
		
		return null;
	}
}

